
package CtrlLayer;
import ModelLayer.Company;
import DBLayer.IFDBCompany; 
import DBLayer.DBCompany;

/**
 * @version 12/22/2011
 * @author Gruppe 4
 */

public class CtrlCompany 
{
    private IFDBCompany dbCompany;
    
    /**
     * Constructor for class CtrlCompany
     */
    public CtrlCompany()
    {
        dbCompany = new DBCompany();
    }
    
    /**
     * Method to find a company with a unique id
     * @param companyId int companyId the id for the company
     * @return returns a Company object
     */
    public Company findCompanyById(int companyId)
    {
        return dbCompany.searchCompanyById(companyId);
    }
    
    /**
     * Method to insert a new company in the database
     * @param company Object Company the company we want to insert in the database
     */
    public void insertCompany(Company company)
    {
        dbCompany.insertCompany(company);
    }
    
    /**
     * Method to update a company in the database
     * @param companyId int companyId the Id of the company
     * @param name String name the name of company
     * @param fName String fName the first name of the man who owns the company
     * @param lName String lName the last name of the man who owns the company
     * @param address String address the address of the company
     * @param zipCode int zipCode the zipCode of the company
     * @param mobileNo String mobileNo the mobile number of the company
     * @param phoneNo String phoneNo the landline of the company
     * @param email String email the email of the company
     * @param cvr String cvr the cvr of the company
     * @return returns an int 1 if the method succedes and -1 if the method fails
     */
    public int updateCompany(int companyId, String name, String fName, String lName, String address, int zipCode, String mobileNo, String phoneNo, String email, String cvr)
    {
         Company comp = new Company();
         comp.setCompanyId(companyId);
         comp.setName(name);
         comp.setFirstName(fName);
         comp.setLastName(lName);
         comp.setAddress(address);
         comp.setZipCode(zipCode);
         comp.setMobileNo(mobileNo);
         comp.setPhoneNo(phoneNo);
         comp.setEmail(email);
         comp.setCvr(cvr);
         return  dbCompany.updateCompany(comp);
    }
    
    /**
     * Method to delete a company from the database
     * @param companyId int companyId the id of the company
     */
    public void deleteCompany(int companyId )
    {
        dbCompany.deleteCompany(companyId);
    }
}